package deployr.core;

import static deployr.domain.NotFound.*;

import java.util.*;

import sun.reflect.generics.reflectiveObjects.*;
import deployr.domain.*;

public class Updates implements Iterable<IUpdate> {

	private List<IUpdate> updates = new LinkedList<IUpdate>();

	private final String commonPath;

	public Updates() {
		commonPath = "updates";
	}

	public Updates(String commonPath) {
		this.commonPath = commonPath;
	}

	public IUpdate addUpdate(IUpdate update) {
		updates.add(update);
		return update;
	}

	protected String commonPath() {
		return commonPath;
	}

	public boolean empty() {
		return updates.isEmpty();
	}

	public Iterator<IUpdate> iterator() {
		return updates.iterator();
	}

	public IUpdate loadByUpdateKey(String updateKey) {
		for (IUpdate update : updates) {
			if (update.getUpdateKey().equals(updateKey)) {
				return update;
			}
		}

		return NotFoundUpdate;
	}

	public void removeUpdate(Update update) {
		updates.remove(update);
	}

	@Override
	public String toString() {
		return updates.toString();
	}

	public void removeUpdate(IUpdate update) {
		updates.remove(update);
	}

	public Iterable<IUpdate> updates(String projectKey) {
		throw new NotImplementedException();
	}

	public IUpdate createAndAddUpdate(IProject project) {
		throw new NotImplementedException();
	}

	public void removeUpdates(String projectKey) {
		throw new NotImplementedException();
	}

	public void save(IUpdate update) {
	}
}
